package com.coska;

/**
 * 一次向10张表插入数据
 */

import java.sql.*;
import java.util.Date;

public class ProcedureTest implements Runnable {

    public static Connection conn = null;

    static {
        String url = "jdbc:postgresql://localhost:5432/postgres"; //数据库连接地址
        String name = "org.postgresql.Driver";
        String user = "postgres";
        String password = "root";//密码
        try {
            Class.forName(name);
            conn = DriverManager.getConnection(url, user, password);
//            conn.setAutoCommit(false);//关闭自动提交
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void run() {
//        long begin = System.currentTimeMillis();
        String sql = "{call insertBatch(?)}";
        CallableStatement pst = null;
        try {
            CallableStatement call = conn.prepareCall(sql);

            for (int i = 0; i < 10; i++) {
                //调用存储过程，设定单个线程循环次数
                call.setInt(1, 1);
                call.execute();

               Thread.sleep(1000);

            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
